Auto-generate rbs_ast_ruby_annotations_t union from config.yml#2939
Open
ksss wants to merge 2 commits intoruby:masterfrom
Open
Auto-generate rbs_ast_ruby_annotations_t union from config.yml#2939ksss wants to merge 2 commits intoruby:masterfrom
ksss wants to merge 2 commits intoruby:masterfrom
Conversation
The union `rbs_ast_ruby_annotations_t` was previously maintained by hand in ast.h.erb with only 6 members, while 14 annotation structs existed and were all cast to this union pointer in parser.c. This drift went unnoticed because downstream code only touches `.base` and never instantiates the union as a value. Generate the union members from the annotation entries in config.yml so future additions stay in sync automatically. As a side benefit, ruby-rbs-sys/build.rs can now allowlist the union type alone and rely on bindgen's transitive allowlisting to pull in every `rbs_ast_ruby_annotations_*_t` member, replacing the hand-maintained list of 13 individual allowlist entries (which had itself drifted by missing module_self_annotation_t). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The previous `allowlist_type("rbs_ast_ruby_annotations_t")` relied on
bindgen's transitive allowlisting through the union. That works against
the current master (where the union lists all 14 annotation members
after auto-generation), but CI vendors the pinned v4.0.2 tag via
`rake rust:rbs:sync`, whose union only has 6 members. The other 7
annotation structs referenced by ruby-rbs therefore never appeared in
bindings.rs, breaking `cargo test`.
Switch to the regex `rbs_ast_ruby_annotations_.*` which matches every
annotation struct directly (and still includes the union itself) in
both the pinned vendor and the current master, preserving the
auto-follow property intended by this PR.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
rbs_ast_ruby_annotations_tunion ininclude/rbs/ast.hwas hand-written with only 6 members, whileast.hdefines 14rbs_ast_ruby_annotations_*_tstructs andsrc/parser.ccasts all 14 torbs_ast_ruby_annotations_t *. The code worked only because downstream consumers (e.g.ext/rbs_extension/ast_translation.c) just read.baseand re-cast to the concrete struct — the union value itself is never instantiated.templates/template.rbto collect nodes underRBS::AST::Ruby::Annotations::*and render the union body from them intemplates/include/rbs/ast.h.erb, so future annotation additions stay in sync automatically.allowlist_typeentries inrust/ruby-rbs-sys/build.rswith a single regexrbs_ast_ruby_annotations_.*, so bindgen picks up every annotation struct (and the union itself) regardless of whether we build against the pinned vendor or the current master. This also silently closes the missing-entry forrbs_ast_ruby_annotations_module_self_annotation_t.Why the Rust drift went unnoticed
rust/ruby-rbs-sys/build.rswas last updated on 2026-03-12;RBS::AST::Ruby::Annotations::ModuleSelfAnnotationwas added toconfig.ymlon 2026-04-06. The Rust CI workflow pinsrbs_version = v4.0.2and vendors that tag viarake rust:rbs:sync, so the CI build consumes aconfig.ymlthat predates the new annotation.cargo buildtherefore only failed for developers who userake rust:rbs:symlinkto work against the current master. After this PR, the regex-based allowlist stays in sync withconfig.ymlon both sides (pinned vendor and master), so adding a new annotation only requires editingconfig.yml.Test plan
bundle exec rake compile(clean, no warnings)bundle exec rake test— 936 tests / 0 failurescargo clean && cargo testunderrake rust:rbs:sync(CI-equivalent setup, pinned v4.0.2 vendor)cargo clean && cargo testunderrake rust:rbs:symlink(masterHEADvendor — previously failed withcannot find type 'rbs_ast_ruby_annotations_module_self_annotation_t')cargo clippy— no warnings in both modesinclude/rbs/ast.hmatches template output afterclang-format(equivalent torake confirm_templates)🤖 Generated with Claude Code